<?php
/**
 * Created by PhpStorm.
 * User: wangjie
 * Date: 2020/4/20
 * Time: 10:38 AM
 */

namespace App\Api\Controllers\Config;


use App\Http\Controllers\Controller;
use App\Models\EasypayaStore;
use App\Models\Store;
use App\Models\EasypayConfig;
use App\Models\EasypayStore;
use Illuminate\Support\Facades\Log;

class EasyPayConfigController extends Controller
{

    public function easypay_config($config_id)
    {
        //配置取缓存
        $config = EasypayConfig::query()
            ->where([
                'config_id' => $config_id,
            ])
            ->first();
        if (!$config) {
            $config = EasypayConfig::where([
                'config_id' => '1234',
            ])->first();
        }

        return $config;
    }


    public function easypay_merchant($store_id, $store_pid,string $version = "easypay")
    {
        $query=EasypayStore::query();
        if($version=="easypaya"){
            $query=EasypayaStore::query();
        }
        if ($store_pid) {
            //分店配置
            $EasypayStore = (clone $query)
                ->where([
                    'store_id' => $store_id,
                ])->first();
            if (!$EasypayStore) {
                $store_pid_id = '';
                $store_p = Store::query()->where('id', $store_pid)
                    ->select('store_id')
                    ->first();
                if ($store_p) {
                    $store_pid_id = $store_p->store_id;
                }
                $EasypayStoreQuery = (clone $query)->where([
                    'store_id' => $store_pid_id,
                ]);
                $EasypayStore=$EasypayStoreQuery->first();
            }
        } else {
            $EasypayStore = (clone $query)->where([
                'store_id' => $store_id,
            ])->first();
        }
        return $EasypayStore;
    }


}
